﻿using Application.AppService.Config;
using Application.AppService.IConfig;
using Application.AppService.IConfig.Dto.EmrDto;
using AutoMapper;
using Domain.Entity.Config;
using Microsoft.AspNetCore.Mvc;
using System.Reflection.Metadata.Ecma335;

namespace UI.Controllers.MoKuaiYi_第一个模块_.Post_Publication_Management_职位发布管理_
{
    public class EMRController : Controller
    {
        private readonly IEngage_major_releaseAppService emrAppService;
        private readonly IMapper mapper;

        public EMRController(IEngage_major_releaseAppService emrAppService, IMapper mapper)
        {
            this.emrAppService = emrAppService;
            this.mapper = mapper;
        }
        //页面1-1
        public IActionResult Index()
        {
            return View();
        }
        //添加
        [HttpPost("AddEMR")]
        public async Task<IActionResult> Add(Engage_major_release emr)
        {
            int rs = await emrAppService.AddEMRAsync(emr);
            return Json(rs);
        }
        //页面1-2
        public IActionResult Index2()
        {
            return View();
        }

        //查询
        [HttpPost]
        public async Task<IActionResult> GetEMR()
        {
            List<Engage_major_release> emrs = await emrAppService.GetEMR();
            return Json(emrs);
        }
        //删除
        [HttpPost("DeleteEMR")]
        public async  Task<IActionResult> DeleteEMR(int Id)
        {
            int i = await emrAppService.DeleteEMRAsync(Id);
            return Json(i);
        }
        //修改
        [HttpPost("UpdateEMR")]
        public  async Task<IActionResult> UpdateEMR(EmrDto emrDto)
        {
            Engage_major_release cmr = mapper.Map<Engage_major_release>(emrDto);
            int i=await emrAppService.UpdateEMRAsync(cmr);
            return Json(i);
        }
        [HttpPost("GetChances")]
        public IActionResult GetChances (int page,int pageSize)
        {
            var totalRecords = emrAppService.GetCount();
            var chances = emrAppService.GetList(page,pageSize);
            return Json(new {TotalRecords = totalRecords,Chances = chances});
        }
    }
}
